package com.haochang.chunkvod.app.utils;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;

public class ActivityTaskUtil
{

	private static volatile ActivityTaskUtil singleton;

	private ActivityTaskUtil()
	{
	}

	public static ActivityTaskUtil getInstance()
	{
		if (singleton == null)
		{
			synchronized (ActivityTaskUtil.class)
			{
				if (singleton == null)
				{
					singleton = new ActivityTaskUtil();
				}
			}
		}
		return singleton;
	}

	/**
	 *
	 * @param context 上下文
	 * @param TAG activity的全名 如：com.activty.loging
	 * @return activity是否处在顶层
	 */
	public boolean isTopActivity(Context context, String TAG)
	{
		ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
		try
		{
			return cn.getClassName().contains(TAG);
		} catch (Exception e)
		{
			return false;
		}
	}
}